<?php 

namespace app\admin\controller;
class Vip extends Comm{
	public function vip_list(){
		$info = model('vip')->alias('v')->join('Village l','l.id=v.area && v.status=1')->select();
		$count = count($info);
		foreach($info as $v){
			$data[] = $v->toArray();
		}
		$this->assign('count',$count);	//vip个数
		$this->assign('data',$data);	//vip列表信息
		return $this->fetch();
	}
	public function vip_show(){
		return $this->fetch();
	}
	public function do_del(){
		$id = $_POST['id'];
		$res = model('Vip')->where(['vid'=>$id])->delete();
		if($res>0){
			$this->success('删除成功');
		}

	}
	//改需求  暂缓----个人
	public function member(){
		$data['uname'] = session('uname');
		$data['status'] = 0;
		model('vip')->where('vid='.input('post.vid'))->update($data);
	}
	//改客需
	public function zan(){
		$data['uname'] = null;
		$data['status'] = 1;
		model('vip')->where('vid='.input('post.vid'))->update($data);
	}
	//个人客需
	public function member_vip(){
		$info = model('vip')->alias('v')
		->join('Village l','l.id=v.area && v.status=0')
		->select();
		foreach($info as $k=>$v){
			$data[] = $v->toArray();
		}
		$count = count($data);
		$this->assign('count',$count);	//vip个数
		$this->assign('data',$data);	//vip列表信息
		return $this->fetch();
	}
	//新增客需
	public function member_add(){
		if(request()->isPost()){
			$data['area'] = input('post.area');
			$data['vname'] = input('post.vname');
			$data['tel'] = input('post.tel');
			$data['uname'] = session('uname');
			model('vip')->allowfield(true)->data($data)->save();
		}
		return $this->fetch();
	}
	//地域三级联动
	public function vill_show(){
		$info = model('village')->where('pid="'.input('post.pid').'"')->select();
		foreach($info as $v){
			$data[] = $v->toArray();
		}
		//dump($data);exit;
		$this->success($data);
	}
	//跟進
	public function vip_follow(){
		if(request()->isPost()){
			$data['content'] = input('post.content');
			$data['uname'] = session('uname');
			$data['date'] = date('Y-m-d H:i:s',time());
			$data['vid'] = input('get.vid');
			model('kexu')->allowfield(true)->data($data)->save();
		}
		$info = model('kexu')->where('vid='.input('get.vid'))->select();
		$data = [];
		foreach($info as $k=>$v){
			$data[] = $v->toArray();
			$data[$k]['sid'] = $k+1;
		}
		$this->assign('data',$data);
		return $this->fetch();
	}
	//刪除跟進 
	public function follow_del(){
		model('kexu')->where('id='.input('post.id'))->delete();
	} 
}